Editing a Geometry Object
This example demonstrates how to modify each part of a multipart geometry. This example uses the IGeometryCreator (CreateGeometryFromWKT), ICreator80 (CreatePolygon, IPosition80 (Distance, Pitch), INavigate80 (JumpTo), and IPolygon(StartEdit, EndEdit) properties and methods.
private void btnEdit()
{
try
{
var SGWorld = new SGWorld80();
var geometry = SGWorld.Creator.GeometryCreator.CreateGeometryFromWKT(@"POLYGON(
(-82.900091 26.739261,-82.906338 26.840896,-82.591731 26.951601,-82.809248 26.717179,-82.900091 26.739261),
(-82.873569 26.819371,-82.81616 26.772908,-82.811242 26.846308,-82.873569 26.819371)
)");
var polygon = SGWorld.Creator.CreatePolygon(geometry, Color.AliceBlue.ToArgb(), Color.Bisque.ToArgb(), AltitudeTypeCode.ATC_TERRAIN_RELATIVE, string.Empty, "Polygon");
polygon.Position.Distance = 80000;
polygon.Position.Pitch = -45;
SGWorld.Navigate.JumpTo(polygon);
MessageBox.Show("Polygon created. Click Ok to move all its points 0.001 to the right on x axis and add z value");
// convert polygon geometry to its type
var polygonGeometry = polygon.Geometry as IPolygon;
// call start edit on the polygon
polygonGeometry.StartEdit();
// iterate over all of its rings. First one is exterior ring. All after it, are interior rings
foreach (ILinearRing ring in polygonGeometry.Rings)
{
foreach (IPoint point in ring.Points)
{
point.X += 0.001;
point.Z += point.X + point.Y;
}
}
// call EndEdit at the end. EndEdit returns new IGeometry. It does so, because IPolygon could have turned to IMultiPolygon
var editedGeometry = polygonGeometry.EndEdit();
// set the new geometry to the object
polygon.Geometry = editedGeometry;
}
catch (Exception ex)
{
MessageBox.Show("Unexpected error: " + ex.Message);
}
}